import { useState } from 'react'
const useWeb = (url: string) => {
    const ws = new WebSocket(url);
    const sendMsg = (msg: string) => {
        ws.send(msg)
    }
    const [data, setData] = useState()
    ws.addEventListener('message', function message(e) {
        setData(e.data)
    })
    return {
        sendMsg,
        data
    }
}

export default useWeb
